//
//  MyViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/16.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "MyViewController.h"
#import "Define.pch"
@interface MyViewController ()

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.likeViewController=[[LikeViewController alloc]init];
    self.buyViewController=[[BuyViewController alloc]init];
    self.forivteViewController=[[ForivteViewController alloc]init];
    self.shareViewController=[[ShareViewController alloc]init];
    
    self.likeViewController.view.frame=CGRectMake(0, 100, SCREENWIDTH, SCREENHEIGHT-100);
    self.buyViewController.view.frame=CGRectMake(0, 100, SCREENWIDTH, SCREENHEIGHT-100);
    self.forivteViewController.view.frame=CGRectMake(0, 100, SCREENWIDTH, SCREENHEIGHT-100);
    self.shareViewController.view.frame=CGRectMake(0, 100, SCREENWIDTH, SCREENHEIGHT-100);
    
    [self addChildViewController:self.likeViewController];
    [self addChildViewController:self.buyViewController];
    [self addChildViewController:self.forivteViewController];
    [self addChildViewController:self.shareViewController];
    
    [self.view addSubview:self.likeViewController.view];
    
    [likeButton setSelected:YES];
    titleLabel.text=@"猜你喜欢";
    self.currentViewController=self.likeViewController;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)showChildView:(UIViewController *)target{
    if (self.currentViewController==target) {
        return;
    }
    UIViewController *oldViewController=self.currentViewController;
    [self transitionFromViewController:self.currentViewController toViewController:target duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{} completion:^(BOOL finished){
        if (finished) {
            self.currentViewController=target;
        }else{
            self.currentViewController=oldViewController;
        }
    }];
}
-(IBAction)likeButton:(id)sender{
    [self showChildView:self.likeViewController];
    [likeButton setSelected:YES];
    [buyButton setSelected:NO];
    [forivteButton setSelected:NO];
    [shareButton setSelected:NO];
    titleLabel.text=@"猜你喜欢";
}
-(IBAction)buyButton:(id)sender{
    [self showChildView:self.buyViewController];
    [likeButton setSelected:NO];
    [buyButton setSelected:YES];
    [forivteButton setSelected:NO];
    [shareButton setSelected:NO];
    titleLabel.text=@"已购买";
}
-(IBAction)forivteButton:(id)sender{
    [self showChildView:self.forivteViewController];
    [likeButton setSelected:NO];
    [buyButton setSelected:NO];
    [forivteButton setSelected:YES];
    [shareButton setSelected:NO];
    titleLabel.text=@"已收藏";
}
-(IBAction)shareButton:(id)sender{
    [self showChildView:self.shareViewController];
    [likeButton setSelected:NO];
    [buyButton setSelected:NO];
    [forivteButton setSelected:NO];
    [shareButton setSelected:YES];
    titleLabel.text=@"已分享";
}
-(IBAction)exit:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
